$(function () {
    $('.submit').on('click', function () {
        var che =  check();
        console.log(che);
        if(che == false){
            return false;
        }else{
            save();
        }
    });
})

/*保存用户*/
function save() {
    var para = new Object();
    para.id = $('input[name="id"]').val();
    para.name = $('input[name="name"]').val();
    para.mobile = $('input[name="mobile"]').val();
    para.address = $('input[name="address"]').val();
    para.balance = $('input[name="balance"]').val();
    para.discount = $('input[name="discount"]').val();
    var data = JSON.stringify(para);

    var url = '?m=index-Customer&do=inUp'
    var data = {
        data: data
    };
    $.ajax({
        url: url,
        type: 'post',
        dataType: 'json',
        data: data,
        success: function (res) {
            console.log(res);
            if (res.code == 200)
            {
                var red_url = "?m=index-Customer&do=index";
                l_succcess(res.message);
                setTimeout(function () {
                    redir_url(red_url);
                }, 1000);
            } else
            {
                l_fail(res.message);
            }
        }
    });
}

/*修改用户*/
function update(id){
    var red_url = "?m=index-Customer&do=update&id="+id;
    redir_url(red_url);
}

/*确认删除*/
function delConfirm(id){
    layui.use(['layer'], function () {
        var layer = layui.layer;
        layer.confirm('确认删除客户?',{"title":"删除确认"},function (){
            delCus(id);
        },function (){
            layer.close();
        });
    });
}

/*删除客户*/
function delCus(id){
    var url = '?m=index-Customer&do=delCus';
    var data = {
        id: id
    };
    $.ajax({
        url: url,
        type: 'post',
        dataType: 'json',
        data: data,
        success: function (res) {
            console.log(res);
            if (res.code == 200)
            {
                var red_url = location.href;;
                l_succcess(res.message);
                setTimeout(function(){
                    redir_url(red_url);
                },1000);
            } else
            {
                l_fail(res.message);
            }
        }
    });
}




